package com.sdx.console.contract.backstage.Utils;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.imageio.ImageIO;

import com.sdx.console.contract.backstage.Utils.HttpUtils;
import com.sdx.console.contract.backstage.Utils.WxInvoiceHandler;
import com.sdx.service.ConfigService;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;

import com.alibaba.fastjson.JSONObject;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpLocation;
import com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpProcessor;


/**
 * 数字转换为汉语中人民币的大写<br>
 * http://www.cnblogs.com/hongten/p/hongten_java_money.html
 *
 * @author hongten
 * @contact hongtenzone@foxmail.com
 * @create 2013-08-13
 */
public class InvoiceUtils {
	//private static final Logger	log		= LoggerFactory.getLogger(InvoiceUtils.class);

	//public static final String	TPLDIR	= "/opt/apache-tomcat-7.0.63/webapps/sdx/u/invoices";
	//public static final String	TPLDIR	= "C:/Users/qinzp/Desktop/图片";
	/**
	 * 汉语中数字大写
	 */
	private static final String[] CN_UPPER_NUMBER = { "零", "壹", "贰", "叁", "肆","伍", "陆", "柒", "捌", "玖" };
	/**
	 * 汉语中货币单位大写，这样的设计类似于占位符
	 */
	private static final String[] CN_UPPER_MONETRAY_UNIT = { "分", "角", "元",
			"拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾",
			"佰", "仟" };
	/**
	 * 特殊字符：整
	 */
	private static final String CN_FULL = "整";
	/**
	 * 特殊字符：负
	 */
	private static final String CN_NEGATIVE = "负";
	/**
	 * 金额的精度，默认值为2
	 */
	private static final int MONEY_PRECISION = 2;
	/**
	 * 特殊字符：零元整
	 */
	private static final String CN_ZEOR_FULL = "零元" + CN_FULL;


	//字体文件
//	/usr/share/fonts/win/SIMSUN.TTC
//	private static final String ttcPath="C:/Users/Administrator/Desktop/pdf/SIMSUN.TTC";
//	private static final String ttcPath= ConfigService.contractfile;
	private static final String ttcPath="/usr/share/fonts/win/SIMSUN.TTC";


	/**
	 * 把输入的金额转换为汉语中人民币的大写
	 *
	 * @param numberOfMoney
	 *            输入的金额
	 * @return 对应的汉语大写
	 */
	public static String number2CNMontrayUnit(BigDecimal numberOfMoney) {
		StringBuffer sb = new StringBuffer();
		// -1, 0, or 1 as the value of this BigDecimal is negative, zero, or
		// positive.
		int signum = numberOfMoney.signum();
		// 零元整的情况
		if (signum == 0) {
			return CN_ZEOR_FULL;
		}
		//这里会进行金额的四舍五入
		long number = numberOfMoney.movePointRight(MONEY_PRECISION)
				.setScale(0, 4).abs().longValue();
		// 得到小数点后两位值
		long scale = number % 100;
		int numUnit = 0;
		int numIndex = 0;
		boolean getZero = false;
		// 判断最后两位数，一共有四中情况：00 = 0, 01 = 1, 10, 11
		if (!(scale > 0)) {
			numIndex = 2;
			number = number / 100;
			getZero = true;
		}
		if ((scale > 0) && (!(scale % 10 > 0))) {
			numIndex = 1;
			number = number / 10;
			getZero = true;
		}
		int zeroSize = 0;
		while (true) {
			if (number <= 0) {
				break;
			}
			// 每次获取到最后一个数
			numUnit = (int) (number % 10);
			if (numUnit > 0) {
				if ((numIndex == 9) && (zeroSize >= 3)) {
					sb.insert(0, CN_UPPER_MONETRAY_UNIT[6]);
				}
				if ((numIndex == 13) && (zeroSize >= 3)) {
					sb.insert(0, CN_UPPER_MONETRAY_UNIT[10]);
				}
				sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]);
				sb.insert(0, CN_UPPER_NUMBER[numUnit]);
				getZero = false;
				zeroSize = 0;
			} else {
				++zeroSize;
				if (!(getZero)) {
					sb.insert(0, CN_UPPER_NUMBER[numUnit]);
				}
				if (numIndex == 2) {
					if (number > 0) {
						sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]);
					}
				} else if (((numIndex - 2) % 4 == 0) && (number % 1000 > 0)) {
					sb.insert(0, CN_UPPER_MONETRAY_UNIT[numIndex]);
				}
				getZero = true;
			}
			// 让number每次都去掉最后一个数
			number = number / 10;
			++numIndex;
		}
		// 如果signum == -1，则说明输入的数字为负数，就在最前面追加特殊字符：负
		if (signum == -1) {
			sb.insert(0, CN_NEGATIVE);
		}
		// 输入的数字小数点后两位为"00"的情况，则要在最后追加特殊字符：整
		if (!(scale > 0)) {
			sb.append(CN_FULL);
		}
		return sb.toString();
	}

  /*  public static void main(String[] args) throws IOException, DocumentException{
	String studentName = "吴法天";
	  String schoolName = "鹤壁高中";
	  String className = "三年二班";
	  String degree = "410603888811082512";
	  String address = "南昌市青山湖区南京东路649号青山湖区公安局治安大队649号青山湖区公安局治安大队";
	  String mailCode = "458000";
	  String phone = "17090098850";
	  String parentName = "吴彦祖";
	  String parentdegree = "410526111111111111";
	  String parentphone = "13811234558";
	  Integer type[] = {2,3,4};
	  Integer fee[] = {1001,2000,3000};
	  Integer prize = 100;
	  Integer dissertation = 200;
	  Integer tuifei1 = 100;
	  Integer tuifei2 = null;
	  Integer tuifei3 = 0;
	  boolean exchange = false;
	  List<Map<Integer, Integer>> list = new ArrayList<Map<Integer,Integer>>();
	  for (int i = 0; i < type.length; i++) {
	        Map<Integer,Integer> map1 = new HashMap<Integer,Integer>();
	        map1.put(type[i], fee[i]);
	        list.add(map1);
	       }
	  String sale_name = "销售人员甲";

	  SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
	  String invoice_no = sdf.format(new Date());

	  new InvoiceUtils().getPdf(tuifei1,tuifei2,tuifei3,exchange,prize,dissertation,studentName, schoolName, className, degree, address, mailCode, phone, parentName, parentdegree, parentphone, list, sale_name, invoice_no, TPLDIR);

	  // String srcFile = "C:/Users/qinzp/Desktop/图片/合同效果20180811183039.pdf";
     String invoice_no = "20180205153810";
	  String srcFile = TPLDIR+invoice_no+"/"+invoice_no+".pdf";
	 // String destPath = "C:/Users/qinzp/Desktop/图片/合同效果20180811183039/";
	  String destPath = TPLDIR+invoice_no+"/";
	  new InvoiceUtils().pdfToImage(srcFile, destPath, null, 196f, false);

	  String imgPath = "C:/Users/qinzp/Documents/水水水水/image2base64.png";

	  new InvoiceUtils().reversalImage(imgPath);

	  String parentName = "陈玲";
	  String parentdegree = "320723198111163464";
	  new InvoiceUtils().checkDegree( parentName,  parentdegree);

	  try {
          // readfile("D:/file");
          deletefile("j:/a");
      } catch (Exception ex) {
          ex.printStackTrace();
      }
      System.out.println("ok");
	  String host = "http://m.51sdx.com";
	    String path = "/sdx-inter/esign/notificationSign";
	    Map<String, String> querys = new HashMap<String, String>();
	    querys.put("parentPhone", "17090098850");
	    querys.put("parentName", "秦振鹏");
	    querys.put("invoiceNo", "20180830124110");
	  new InvoiceUtils().doPostSMS(host, path, null, querys);
  }*/


	public  void getPdfBaoguo(Integer tuifei1,Integer tuifei2,Integer tuifei3,boolean exchange,Integer prize,Integer dissertation,String studentName,String schoolName,String className,String degree,String address,String mailCode,String phone,
							  String parentName,String parentdegree,String parentphone,List<Map<Integer, Integer>> list,String sale_name,String invoice_no, String destPath ) throws IOException, DocumentException {
		Map<Integer, Integer>  zzzs = new HashMap<Integer,Integer>();
		Map<Integer, Integer>  zytb = new HashMap<Integer,Integer>();
		Map<Integer, Integer>  gat = new HashMap<Integer,Integer>();
		Map<Integer, Integer>  zzzsbg = new HashMap<Integer,Integer>();
		Map<Integer, Integer>  zhpj = new HashMap<Integer,Integer>();
		Map<Integer, Integer>  other = new HashMap<Integer,Integer>();//其他

		Integer otherMoney =  0;
		dissertation = 0;//论文不再使用，直接设置为0
		for(Map<Integer, Integer> j : list){

			if(j.containsKey(1)){
				zzzs.put(1, j.get(1));
			}
			if(j.containsKey(2)){
				zytb.put(2, j.get(2));
			}
			if(j.containsKey(3)){
				gat.put(3, j.get(3));
			}
			if(j.containsKey(4)){
				zzzsbg.put(4, j.get(4));
			}
			if(j.containsKey(5)){
				zhpj.put(5, j.get(5));
			}
			if(j.containsKey(6)){
				other.put(6, j.get(6));
				otherMoney = Integer.valueOf(j.get(6));
			}
		}

		//创建一个pdf读入流
		PdfReader reader = new PdfReader(destPath+"/"+"invoiceTemplateBaoguo.pdf");

		//根据一个pdfreader创建一个pdfStamper.用来生成新的pdf.
		File tempFile = new File(destPath+"/"+invoice_no+"/");
		if (!tempFile.exists()) {
			tempFile.mkdirs();
		}
		PdfStamper stamper = new PdfStamper(reader,  new FileOutputStream(destPath+"/"+invoice_no+"/"+invoice_no+".pdf"));

		// BaseFont bfChinese = BaseFont.createFont("STSong-Light,Bold", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
		BaseFont bfChinese = BaseFont.createFont(ttcPath+",1",BaseFont.IDENTITY_H,  BaseFont.NOT_EMBEDDED);
		for (int i=1; i<=reader.getNumberOfPages(); i++){
			//获得pdfstamper在当前页的上层打印内容.也就是说 这些内容会覆盖在原先的pdf内容之上.
			PdfContentByte content = stamper.getUnderContent(i);
			//查看页面坐标范围
			//Rectangle pagesize = reader.getPageSizeWithRotation(1);
			//System.out.println("宽度"+pagesize.getWidth()+"高度"+pagesize.getHeight());
			content.beginText();
			content.setColorFill(BaseColor.BLACK);
			if (i==1) {//封面
				content.setFontAndSize(bfChinese, 14);
				content.setTextMatrix(410, 730);
				content.showText(invoice_no);
				content.setFontAndSize(bfChinese, 17);
				content.setTextMatrix(230, 168);
				content.showText(invoice_no.substring(2,4));
				content.setTextMatrix(292, 168);
				content.showText(invoice_no.substring(4,6));
				content.setTextMatrix(348, 168);
				content.showText(invoice_no.substring(6,8));
				content.endText();
			}

			if (i==2) {//家长信息
				content.setFontAndSize(bfChinese, 12);
				content.setTextMatrix(245, 542);
				content.showText(parentName);
				content.setTextMatrix(160, 494);
				content.showText(parentdegree);
				content.setTextMatrix(160, 470);
				if (address.length()<=38) {
					content.showText(address);
				}else{
					content.showText(address.substring(0,38));
				}
				content.setTextMatrix(160, 448);
				content.showText(mailCode);
				content.setTextMatrix(160, 424);
				content.showText(parentphone);

				//学生信息
				content.setTextMatrix(378,377);
				content.showText(studentName);
				content.setTextMatrix(128,354);
				content.showText(schoolName);
				content.setTextMatrix(376,354);
				content.showText(className);
				content.setTextMatrix(160,330);
				content.showText(degree);
				content.setTextMatrix(160, 307);
				if (address.length()<=38) {
					content.showText(address);
				}else{
					content.showText(address.substring(0,38));
				}
				content.setTextMatrix(160, 284);
				content.showText(mailCode);
				content.setTextMatrix(160, 261);
				content.showText(phone);
				content.endText();
			}

			if (i==3) {//服务项目及费用
				double fee1 = 0;
				double fee2 = 0;
				double fee3 = 0;
				double fee4 = 0;
				double fee5 = 0;
				//自主招生
			   /* if(null!=zzzs&&zzzs.size()!=0){
			    	content.setColorFill(BaseColor.BLACK);
			    	//删除原来的方块
			    	List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
			        cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(110f, 622f, 122f, 642f), BaseColor.WHITE));
			        PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
			        cleaner.cleanUp();

			    	// 读图片
			        // Image image = Image.getInstance("C:/Users/qinzp/Desktop/图片/select.png");
			        // 根据域的大小缩放图片
			        // image.scaleToFit(13, 13);
			        // 添加图片
			        // image.setAbsolutePosition(115,678);
			        // content.addImage(image);
			        content.setFontAndSize(bfChinese, 16);
			        content.setTextMatrix(109,632);
					content.showText("□");
					content.setTextMatrix(109,632);
				    content.showText("√");

					content.setFontAndSize(bfChinese, 12);
			    	double money =zzzs.get(1);
			    	DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
			    	String mon=decimalFormat.format(money);//format 返回的是字符串
			    	content.setTextMatrix(193,614);
			    	content.showText(mon+"");

    	            BigDecimal numberOfMoney = new BigDecimal(money);
    	            String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
    	            content.setTextMatrix(311, 614);
    	            content.showText(s);

    	            fee1 = money;
    	         } else{
    	        	 content.setColorFill(BaseColor.BLACK);
    	        	 content.setLineWidth(0.5f);
    	        	 content.ellipse(195, 615, 244, 615);
    	        	 content.stroke();
    	        	 content.ellipse(340, 615, 460, 615);
    	        	 content.stroke();
	             }*/

				//自主招生保过型
				if(null!=zzzsbg&&zzzsbg.size()!=0){
					content.setColorFill(BaseColor.BLACK);
					//删除原来的方块
					List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
					cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(110f, 622f, 122f, 642f), BaseColor.WHITE));
					PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
					cleaner.cleanUp();

					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(109,632);
					content.showText("□");
					content.setTextMatrix(109,632);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					double money =zzzsbg.get(4);
					DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
					String mon=decimalFormat.format(money);//format 返回的是字符串
					content.setTextMatrix(193,614);
					content.showText(mon+"");

					BigDecimal numberOfMoney = new BigDecimal(money);
					String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
					content.setTextMatrix(311, 614);
					content.showText(s);

					fee4 = money;
				} else{
					content.setColorFill(BaseColor.BLACK);
					content.setLineWidth(0.5f);
					content.ellipse(195, 615, 244, 615);
					content.stroke();
					content.ellipse(340, 615, 460, 615);
					content.stroke();
				}
				//志愿填报
				if(null!=zytb&&zytb.size()!=0){
					content.setColorFill(BaseColor.BLACK);
					//删除原来的方块
					List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
					cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(110f, 670f, 122f, 690f), BaseColor.WHITE));
					PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
					cleaner.cleanUp();

					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(109,678);
					content.showText("□");
					content.setTextMatrix(109,678);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					double money =zytb.get(2);
					DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
					String mon=decimalFormat.format(money);//format 返回的是字符串
					content.setTextMatrix(193,660);
					content.showText(mon+"");

					BigDecimal numberOfMoney = new BigDecimal(money);
					String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
					content.setTextMatrix(311, 660);
					content.showText(s);

					fee2 = money;
				} else{
					content.setColorFill(BaseColor.BLACK);
					content.setLineWidth(0.5f);
					content.ellipse(195, 664, 244, 664);
					content.stroke();
					content.ellipse(340, 664, 460, 664);
					content.stroke();
				}
				//港澳台
				if(null!=gat&&gat.size()!=0){
					content.setColorFill(BaseColor.BLACK);
					//删除原来的方块
					List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
					cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(109f, 535f, 122f, 553f), BaseColor.WHITE));
					PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
					cleaner.cleanUp();

					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(109,538);
					content.showText("□");
					content.setTextMatrix(109,538);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					double money =gat.get(3);
					DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
					String mon=decimalFormat.format(money);//format 返回的是字符串
					content.setTextMatrix(193,520);
					content.showText(mon+"");

					BigDecimal numberOfMoney = new BigDecimal(money);
					String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
					content.setTextMatrix(311, 520);
					content.showText(s);

					fee3 = money;
				} else{
					content.setColorFill(BaseColor.BLACK);
					content.setLineWidth(0.5f);
					content.ellipse(195, 522, 244, 522);
					content.stroke();
					content.ellipse(340, 522, 460, 522);
					content.stroke();
				}
				//综合素质评价
				if(null!=zhpj&&zhpj.size()!=0){
					content.setColorFill(BaseColor.BLACK);
					//删除原来的方块
					List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
					cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(109f, 578.5f, 122f, 597.5f), BaseColor.WHITE));
					PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
					cleaner.cleanUp();

					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(109,585);
					content.showText("□");
					content.setTextMatrix(109,585);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					double money =zhpj.get(5);
					DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
					String mon=decimalFormat.format(money);//format 返回的是字符串
					content.setTextMatrix(193,567);
					content.showText(mon+"");

					BigDecimal numberOfMoney = new BigDecimal(money);
					String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
					content.setTextMatrix(311, 567);
					content.showText(s);

					fee5 = money;
				} else{
					content.setColorFill(BaseColor.BLACK);
					content.setLineWidth(0.5f);
					content.ellipse(195, 568.5, 244, 568.5);
					content.stroke();
					content.ellipse(340, 568.5, 460, 568.5);
					content.stroke();
				}
				//没有自主招生和综合评价奖项为空
//			    if(dissertation==null||dissertation==0){
//			    	 content.setColorFill(BaseColor.BLACK);
//		        	 content.setLineWidth(0.5f);
//
//		        	 content.ellipse(195, 476, 244, 476);
//		        	 content.stroke();
//		        	 content.ellipse(340, 476, 460, 476);
//		        	 content.stroke();
//
//			    }
				if(prize==null||prize==0){
					content.setColorFill(BaseColor.BLACK);
					content.setLineWidth(0.5f);
					content.ellipse(195, 430, 244, 430);
					content.stroke();
					content.ellipse(340, 430, 460, 430);
					content.stroke();

				}
				//奖项和论文
				if(zzzs.get(1)==null&&zzzsbg.get(4)==null&&zhpj.get(5)==null){
					prize = 0;
					dissertation = 0;
				}
				//删除原来的方块
				List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
//			    	if (dissertation!=null&&dissertation>0) {
//			    		cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(109f, 487f, 122f, 505f), BaseColor.WHITE));
//					}

				if (prize!=null&&prize>0) {
					cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(109f, 443f, 122f, 460f), BaseColor.WHITE));
				}
				PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
				cleaner.cleanUp();
				//写入论文
				content.setColorFill(BaseColor.BLACK);

//			    	if (dissertation!=null&&dissertation>0) {
//				        content.setFontAndSize(bfChinese, 16);
//				        content.setTextMatrix(109,490);
//						content.showText("□");
//						content.setTextMatrix(109,490);
//					    content.showText("√");
//
//						content.setFontAndSize(bfChinese, 12);
//				    	double money =dissertation;
//				    	DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
//				    	String mon=decimalFormat.format(money);//format 返回的是字符串
//				    	content.setTextMatrix(193,472);
//				    	content.showText(mon+"");
//
//	    	            BigDecimal numberOfMoney = new BigDecimal(money);
//	    	            String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
//	    	            content.setTextMatrix(311, 472);
//	    	            content.showText(s);
//			    	}
				if(otherMoney==null||otherMoney==0){// 如果其他的金额为空或0， 把原来论文的位置划横线
					content.setColorFill(BaseColor.BLACK);
					content.setLineWidth(0.5f);

					content.ellipse(195, 476, 244, 476);
					content.stroke();
					content.ellipse(340, 476, 460, 476);
					content.stroke();
				}

				if (other!=null&&other.size()>0) {
					content.setFontAndSize(bfChinese, 16);
//					 content.setTextMatrix(109,490);
//					 content.showText("□");
					content.setTextMatrix(109,490);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					double money6 =otherMoney;
					DecimalFormat decimalFormat=new DecimalFormat(".00");
					String mon6=decimalFormat.format(money6);//format 返回的是字符串
					content.setTextMatrix(193,472);
					content.showText(mon6+"");

					BigDecimal numberOfMoney2 = new BigDecimal(money6);
					String s2 = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney2);
					content.setTextMatrix(311, 472);
					content.showText(s2);
				}


				//写入奖项
				if (prize!=null&&prize>0) {
					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(109,446);
					content.showText("□");
					content.setTextMatrix(109,446);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					double money2 =prize;
					DecimalFormat decimalFormat=new DecimalFormat(".00");
					String mon2=decimalFormat.format(money2);//format 返回的是字符串
					content.setTextMatrix(193,427);
					content.showText(mon2+"");

					BigDecimal numberOfMoney2 = new BigDecimal(money2);
					String s2 = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney2);
					content.setTextMatrix(311, 427);
					content.showText(s2);
				}

				//总价
				content.setFontAndSize(bfChinese, 12);
				double total = fee1+fee2+fee3+fee4+fee5+(prize==null?0:prize)+otherMoney;//(dissertation==null?0:dissertation)
				DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
				String tol=decimalFormat.format(total);//format 返回的是字符串
				content.setTextMatrix(211,382);
				content.showText(tol+"");

				BigDecimal numberOfMoney = new BigDecimal(total);
				String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
				content.setTextMatrix(342, 382);
				content.showText(s);
			}

			if (i==4) {
				//退费
				if(zzzsbg.get(4)==null){
					tuifei1 = 0;
					tuifei2 = 0;
					tuifei3 = 0;
					exchange = false;
				}
				if(null!=tuifei1&&0!=tuifei1){
					content.setColorFill(BaseColor.BLACK);
					//删除原来的方块
					List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
					cleanUpLocations.add(new PdfCleanUpLocation(4, new Rectangle(125f, 543f, 135f, 554), BaseColor.WHITE));
					PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
					cleaner.cleanUp();

					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(125,541);
					content.showText("□");
					content.setTextMatrix(125,541);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
					String mon=decimalFormat.format(tuifei1);//format 返回的是字符串
					content.setTextMatrix(219,500);
					content.showText(mon+"");

					BigDecimal numberOfMoney = new BigDecimal(tuifei1);
					String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
					content.setTextMatrix(349, 500);
					content.showText(s);
				}else{
					content.setLineWidth(0.5f);
					content.ellipse(220, 503, 262, 503);
					content.stroke();
					content.ellipse(350, 503, 450, 503);
					content.stroke();
				}
				if(null!=tuifei2&&0!=tuifei2){
					content.setColorFill(BaseColor.BLACK);
					//删除原来的方块
					List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
					cleanUpLocations.add(new PdfCleanUpLocation(4, new Rectangle(125f, 470f, 135f, 485f), BaseColor.WHITE));
					PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
					cleaner.cleanUp();

					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(125,470);
					content.showText("□");
					content.setTextMatrix(125,470);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
					String mon=decimalFormat.format(tuifei2);//format 返回的是字符串
					content.setTextMatrix(219,455);
					content.showText(mon+"");

					BigDecimal numberOfMoney = new BigDecimal(tuifei2);
					String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
					content.setTextMatrix(349, 455);
					content.showText(s);
				}else{
					content.setLineWidth(0.5f);
					content.ellipse(220, 457, 262, 457);
					content.stroke();
					content.ellipse(350, 457, 450, 457);
					content.stroke();
				}
				if(null!=tuifei3&&0!=tuifei3){
					content.setColorFill(BaseColor.BLACK);
					//删除原来的方块
					List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
					cleanUpLocations.add(new PdfCleanUpLocation(4, new Rectangle(125f, 425f, 135f, 436f), BaseColor.WHITE));
					PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
					cleaner.cleanUp();

					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(125,425);
					content.showText("□");
					content.setTextMatrix(125,425);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
					String mon=decimalFormat.format(tuifei3);//format 返回的是字符串
					content.setTextMatrix(219,406);
					content.showText(mon+"");

					BigDecimal numberOfMoney = new BigDecimal(tuifei3);
					String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
					content.setTextMatrix(349, 406);
					content.showText(s);
				}else{
					content.setLineWidth(0.5f);
					content.ellipse(220, 411, 262, 411);
					content.stroke();
					content.ellipse(350, 411, 450, 411);
					content.stroke();
				}
				if(exchange){
					content.setColorFill(BaseColor.BLACK);
					//删除原来的方块
					List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
					cleanUpLocations.add(new PdfCleanUpLocation(4, new Rectangle(125f, 376f, 135f, 392f), BaseColor.WHITE));
					PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
					cleaner.cleanUp();

					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(125,376);
					content.showText("□");
					content.setTextMatrix(125,376);
					content.showText("√");
				}
			}

			if (i==9) {//签字
				content.setFontAndSize(bfChinese, 12);
				content.setTextMatrix(158, 364);
				content.showText(invoice_no.substring(2,4));
				content.setTextMatrix(186, 364);
				content.showText(invoice_no.substring(4,6));
				content.setTextMatrix(212, 364);
				content.showText(invoice_no.substring(6,8));

				content.setTextMatrix(421, 364);
				content.showText(invoice_no.substring(2,4));
				content.setTextMatrix(446, 364);
				content.showText(invoice_no.substring(4,6));
				content.setTextMatrix(471, 364);
				content.showText(invoice_no.substring(6,8));

				content.setFontAndSize(bfChinese, 14);
				content.setTextMatrix(189, 334);
				content.showText(sale_name);
			}
		}
		stamper.close();
		reader.close();
	}

	public  void getPdfNoBaoguo(Integer tuifei1,Integer tuifei2,Integer tuifei3,boolean exchange,Integer prize,Integer dissertation,String studentName,String schoolName,String className,String degree,String address,String mailCode,String phone,
								String parentName,String parentdegree,String parentphone,List<Map<Integer, Integer>> list,String sale_name,String invoice_no, String destPath) throws IOException, DocumentException {
		Map<Integer, Integer>  zzzs = new HashMap<Integer,Integer>();
		Map<Integer, Integer>  zytb = new HashMap<Integer,Integer>();
		Map<Integer, Integer>  gat = new HashMap<Integer,Integer>();
		Map<Integer, Integer>  zzzsbg = new HashMap<Integer,Integer>();
		Map<Integer, Integer>  zhpj = new HashMap<Integer,Integer>();
		Map<Integer, Integer>  other = new HashMap<Integer,Integer>();//其他

		//论文 不再使用，直接把论文金额设置为0
		Integer otherMoney = 0;
		dissertation=0;

		for(Map<Integer, Integer> j : list){

			if(j.containsKey(1)){
				zzzs.put(1, j.get(1));
			}
			if(j.containsKey(2)){
				zytb.put(2, j.get(2));
			}
			if(j.containsKey(3)){
				gat.put(3, j.get(3));
			}
			if(j.containsKey(4)){
				zzzsbg.put(4, j.get(4));
			}
			if(j.containsKey(5)){
				zhpj.put(5, j.get(5));
			}
			if(j.containsKey(6)){
				other.put(6, j.get(6));
				otherMoney = Integer.valueOf(j.get(6));
			}
		}


		//创建一个pdf读入流
		PdfReader reader = new PdfReader(destPath+"/"+"invoiceTemplateNoBaoguo.pdf");

		//根据一个pdfreader创建一个pdfStamper.用来生成新的pdf.
		File tempFile = new File(destPath+"/"+invoice_no+"/");
		if (!tempFile.exists()) {
			tempFile.mkdirs();
		}
		PdfStamper stamper = new PdfStamper(reader,  new FileOutputStream(destPath+"/"+invoice_no+"/"+invoice_no+".pdf"));

		// BaseFont bfChinese = BaseFont.createFont("STSong-Light,Bold", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
		BaseFont bfChinese = BaseFont.createFont(ttcPath+",1",BaseFont.IDENTITY_H,  BaseFont.NOT_EMBEDDED);
		for (int i=1; i<=reader.getNumberOfPages(); i++){
			//获得pdfstamper在当前页的上层打印内容.也就是说 这些内容会覆盖在原先的pdf内容之上.
			PdfContentByte content = stamper.getUnderContent(i);
			//查看页面坐标范围
			//Rectangle pagesize = reader.getPageSizeWithRotation(1);
			//System.out.println("宽度"+pagesize.getWidth()+"高度"+pagesize.getHeight());
			content.beginText();
			content.setColorFill(BaseColor.BLACK);
			if (i==1) {//封面
				content.setFontAndSize(bfChinese, 14);
				content.setTextMatrix(410, 730);
				content.showText(invoice_no);
				content.setFontAndSize(bfChinese, 17);
				content.setTextMatrix(230, 168);
				content.showText(invoice_no.substring(2,4));
				content.setTextMatrix(292, 168);
				content.showText(invoice_no.substring(4,6));
				content.setTextMatrix(348, 168);
				content.showText(invoice_no.substring(6,8));
				content.endText();
			}

			if (i==2) {//家长信息
				content.setFontAndSize(bfChinese, 12);
				content.setTextMatrix(245, 542);
				content.showText(parentName);
				content.setTextMatrix(160, 494);
				content.showText(parentdegree);
				content.setTextMatrix(160, 470);
				if (address.length()<=38) {
					content.showText(address);
				}else{
					content.showText(address.substring(0,38));
				}
				content.setTextMatrix(160, 448);
				content.showText(mailCode);
				content.setTextMatrix(160, 424);
				content.showText(parentphone);

				//学生信息
				content.setTextMatrix(378,377);
				content.showText(studentName);
				content.setTextMatrix(128,354);
				content.showText(schoolName);
				content.setTextMatrix(376,354);
				content.showText(className);
				content.setTextMatrix(160,330);
				content.showText(degree);
				content.setTextMatrix(160, 307);
				if (address.length()<=38) {
					content.showText(address);
				}else{
					content.showText(address.substring(0,38));
				}
				content.setTextMatrix(160, 284);
				content.showText(mailCode);
				content.setTextMatrix(160, 261);
				content.showText(phone);
				content.endText();
			}

			if (i==3) {//服务项目及费用
				double fee1 = 0;
				double fee2 = 0;
				double fee3 = 0;
				double fee4 = 0;
				double fee5 = 0;
				//自主招生
				if(null!=zzzs&&zzzs.size()!=0){
					content.setColorFill(BaseColor.BLACK);
					//删除原来的方块
					List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
					cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(110f, 622f, 122f, 642f), BaseColor.WHITE));
					PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
					cleaner.cleanUp();

					// 读图片
					// Image image = Image.getInstance("C:/Users/qinzp/Desktop/图片/select.png");
					// 根据域的大小缩放图片
					// image.scaleToFit(13, 13);
					// 添加图片
					// image.setAbsolutePosition(115,678);
					// content.addImage(image);
					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(109,632);
					content.showText("□");
					content.setTextMatrix(109,632);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					double money =zzzs.get(1);
					DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
					String mon=decimalFormat.format(money);//format 返回的是字符串
					content.setTextMatrix(193,614);
					content.showText(mon+"");

					BigDecimal numberOfMoney = new BigDecimal(money);
					String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
					content.setTextMatrix(311, 614);
					content.showText(s);

					fee1 = money;
				} else{
					content.setColorFill(BaseColor.BLACK);
					content.setLineWidth(0.5f);
					content.ellipse(195, 615, 244, 615);
					content.stroke();
					content.ellipse(340, 615, 460, 615);
					content.stroke();
				}

				//自主招生保过型
				  /*  if(null!=zzzsbg&&zzzsbg.size()!=0){
				    	content.setColorFill(BaseColor.BLACK);
				    	//删除原来的方块
				    	List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
				        cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(110f, 622f, 122f, 642f), BaseColor.WHITE));
				        PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
				        cleaner.cleanUp();

				        content.setFontAndSize(bfChinese, 16);
				        content.setTextMatrix(109,632);
						content.showText("□");
						content.setTextMatrix(109,632);
					    content.showText("√");

						content.setFontAndSize(bfChinese, 12);
				    	double money =zzzsbg.get(4);
				    	DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
				    	String mon=decimalFormat.format(money);//format 返回的是字符串
				    	content.setTextMatrix(193,614);
				    	content.showText(mon+"");

	    	            BigDecimal numberOfMoney = new BigDecimal(money);
	    	            String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
	    	            content.setTextMatrix(311, 614);
	    	            content.showText(s);

	    	            fee4 = money;
	    	         } else{
	    	        	 content.setColorFill(BaseColor.BLACK);
	    	        	 content.setLineWidth(0.5f);
	    	        	 content.ellipse(195, 615, 244, 615);
	    	        	 content.stroke();
	    	        	 content.ellipse(340, 615, 460, 615);
	    	        	 content.stroke();
		             }*/
				//志愿填报
				if(null!=zytb&&zytb.size()!=0){
					content.setColorFill(BaseColor.BLACK);
					//删除原来的方块
					List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
					cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(110f, 670f, 122f, 690f), BaseColor.WHITE));
					PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
					cleaner.cleanUp();

					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(109,678);
					content.showText("□");
					content.setTextMatrix(109,678);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					double money =zytb.get(2);
					DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
					String mon=decimalFormat.format(money);//format 返回的是字符串
					content.setTextMatrix(193,660);
					content.showText(mon+"");

					BigDecimal numberOfMoney = new BigDecimal(money);
					String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
					content.setTextMatrix(311, 660);
					content.showText(s);

					fee2 = money;
				} else{
					content.setColorFill(BaseColor.BLACK);
					content.setLineWidth(0.5f);
					content.ellipse(195, 664, 244, 664);
					content.stroke();
					content.ellipse(340, 664, 460, 664);
					content.stroke();
				}
				//港澳台
				if(null!=gat&&gat.size()!=0){
					content.setColorFill(BaseColor.BLACK);
					//删除原来的方块
					List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
					cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(109f, 535f, 122f, 553f), BaseColor.WHITE));
					PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
					cleaner.cleanUp();

					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(109,538);
					content.showText("□");
					content.setTextMatrix(109,538);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					double money =gat.get(3);
					DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
					String mon=decimalFormat.format(money);//format 返回的是字符串
					content.setTextMatrix(193,520);
					content.showText(mon+"");

					BigDecimal numberOfMoney = new BigDecimal(money);
					String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
					content.setTextMatrix(311, 520);
					content.showText(s);

					fee3 = money;
				} else{
					content.setColorFill(BaseColor.BLACK);
					content.setLineWidth(0.5f);
					content.ellipse(195, 522, 244, 522);
					content.stroke();
					content.ellipse(340, 522, 460, 522);
					content.stroke();
				}
				//综合素质评价
				if(null!=zhpj&&zhpj.size()!=0){
					content.setColorFill(BaseColor.BLACK);
					//删除原来的方块
					List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
					cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(109f, 578.5f, 122f, 597.5f), BaseColor.WHITE));
					PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
					cleaner.cleanUp();

					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(109,585);
					content.showText("□");
					content.setTextMatrix(109,585);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					double money =zhpj.get(5);
					DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
					String mon=decimalFormat.format(money);//format 返回的是字符串
					content.setTextMatrix(193,567);
					content.showText(mon+"");

					BigDecimal numberOfMoney = new BigDecimal(money);
					String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
					content.setTextMatrix(311, 567);
					content.showText(s);

					fee5 = money;
				} else{
					content.setColorFill(BaseColor.BLACK);
					content.setLineWidth(0.5f);
					content.ellipse(195, 568.5, 244, 568.5);
					content.stroke();
					content.ellipse(340, 568.5, 460, 568.5);
					content.stroke();
				}

				if(prize==null||prize==0){
					content.setColorFill(BaseColor.BLACK);
					content.setLineWidth(0.5f);
					content.ellipse(195, 430, 244, 430);
					content.stroke();
					content.ellipse(340, 430, 460, 430);
					content.stroke();

				}
				//奖项和论文

				//没有自主招生和综合评价论文为空
//				 if(dissertation==null||dissertation==0){
//					 content.setColorFill(BaseColor.BLACK);
//					 content.setLineWidth(0.5f);
//
//					 content.ellipse(195, 476, 244, 476);
//					 content.stroke();
//					 content.ellipse(340, 476, 460, 476);
//					 content.stroke();
//
//				 }

				if(zzzs.get(1)==null&&zzzsbg.get(4)==null&&zhpj.get(5)==null){
					prize = 0;
					dissertation = 0;
				}
				//删除原来的方块
				List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
//				    	if (dissertation!=null&&dissertation>0) {
//				    		cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(109f, 487f, 122f, 505f), BaseColor.WHITE));
//						}
				if (prize!=null&&prize>0) {
					cleanUpLocations.add(new PdfCleanUpLocation(3, new Rectangle(109f, 443f, 122f, 460f), BaseColor.WHITE));
				}
				PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
				cleaner.cleanUp();
				//写入论文
				content.setColorFill(BaseColor.BLACK);

				//论文功能替换为其他选项，因此注释
//				    	if (dissertation!=null&&dissertation>0) {
//					        content.setFontAndSize(bfChinese, 16);
//					        content.setTextMatrix(109,490);
//							content.showText("□");
//							content.setTextMatrix(109,490);
//						    content.showText("√");
//
//							content.setFontAndSize(bfChinese, 12);
//					    	double money =dissertation;
//					    	DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
//					    	String mon=decimalFormat.format(money);//format 返回的是字符串
//					    	content.setTextMatrix(193,472);
//					    	content.showText(mon+"");
//
//		    	            BigDecimal numberOfMoney = new BigDecimal(money);
//		    	            String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
//		    	            content.setTextMatrix(311, 472);
//		    	            content.showText(s);
//				    	}

				if(otherMoney==null||otherMoney==0){// 如果其他的金额为空或0， 把原来论文的位置划横线
					content.setColorFill(BaseColor.BLACK);
					content.setLineWidth(0.5f);

					content.ellipse(195, 476, 244, 476);
					content.stroke();
					content.ellipse(340, 476, 460, 476);
					content.stroke();

				}

				if (other!=null&&other.size()>0) {
					content.setFontAndSize(bfChinese, 16);
//					 content.setTextMatrix(109,490);
//					 content.showText("□");
					content.setTextMatrix(109,490);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					double money6 =otherMoney;
					DecimalFormat decimalFormat=new DecimalFormat(".00");
					String mon6=decimalFormat.format(money6);//format 返回的是字符串
					content.setTextMatrix(193,472);
					content.showText(mon6+"");

					BigDecimal numberOfMoney2 = new BigDecimal(money6);
					String s2 = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney2);
					content.setTextMatrix(311, 472);
					content.showText(s2);
				}

				//写入奖项
				if (prize!=null&&prize>0) {
					content.setFontAndSize(bfChinese, 16);
					content.setTextMatrix(109,446);
					content.showText("□");
					content.setTextMatrix(109,446);
					content.showText("√");

					content.setFontAndSize(bfChinese, 12);
					double money2 =prize;
					DecimalFormat decimalFormat=new DecimalFormat(".00");
					String mon2=decimalFormat.format(money2);//format 返回的是字符串
					content.setTextMatrix(193,427);
					content.showText(mon2+"");

					BigDecimal numberOfMoney2 = new BigDecimal(money2);
					String s2 = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney2);
					content.setTextMatrix(311, 427);
					content.showText(s2);
				}

				/**
				 * 写入其他
				 * 因为其他这个选项是后来加上去的，且急着需要，
				 * 所以就把很久不用的论文选项直接改成了其他。
				 * 需要先判断论文选项是否有内容。如果没有在把其他写入进去，如果有则不写入，防止合同乱掉。
				 * 此功能后续需改进
				 *
				 * 总价格也是先判断论文价格，再添加的
				 */

				//总价
				content.setFontAndSize(bfChinese, 12);
				double total = fee1+fee2+fee3+fee4+fee5+(prize==null?0:prize)+otherMoney;//+(dissertation==null?0:dissertation)
				DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
				String tol=decimalFormat.format(total);//format 返回的是字符串
				content.setTextMatrix(211,382);
				content.showText(tol+"");

				BigDecimal numberOfMoney = new BigDecimal(total);
				String s = WxInvoiceHandler.number2CNMontrayUnit(numberOfMoney);
				content.setTextMatrix(342, 382);
				content.showText(s);
			}



			if (i==9) {//签字
				content.setFontAndSize(bfChinese, 12);
				content.setTextMatrix(158, 364);
				content.showText(invoice_no.substring(2,4));
				content.setTextMatrix(186, 364);
				content.showText(invoice_no.substring(4,6));
				content.setTextMatrix(212, 364);
				content.showText(invoice_no.substring(6,8));

				content.setTextMatrix(421, 364);
				content.showText(invoice_no.substring(2,4));
				content.setTextMatrix(446, 364);
				content.showText(invoice_no.substring(4,6));
				content.setTextMatrix(471, 364);
				content.showText(invoice_no.substring(6,8));

				content.setFontAndSize(bfChinese, 14);
				content.setTextMatrix(189, 334);
				content.showText(sale_name);
			}
		}
		stamper.close();
		reader.close();
	}

	/**
	 * pdf转图片
	 * @param srcFile pdf转换源文件
	 * @param destPath 图片输出目标路径，为空时默认源文件所在的文件夹
	 * @param format 待输出图片的格式，默认jpg
	 * @param dpi 分辨率，默认96
	 * @param merge 是否合并为一张，默认为每页生成一张图片
	 * @throws IOException
	 */
	public void pdfToImage(String srcFile, String destPath, String format, Float dpi, Boolean merge) throws IOException {
		System.out.println("开始imgs");
		File file = new File(srcFile);
		//默认输出路径为源文件所在文件夹
      /*  if(destPath == null || destPath.isEmpty()){
            destPath = file.getParent();
        }*/
		File tempFile = new File(destPath);
		if (!tempFile.exists()) {
			tempFile.mkdirs();
		}
		List<BufferedImage> images = pdfToImage(file, dpi == null ? 96f : dpi);
		if(images == null || images.isEmpty()){
			return ;
		}
		//默认为jpg
		format = format == null || format.isEmpty() ? "jpg" : format;
		String pdfFileName = file.getName();
		pdfFileName = pdfFileName.substring(0, pdfFileName.indexOf('.'));
		StringBuilder sb = new StringBuilder();
		//合并多张图片为一张
		merge = merge == null ? false : merge;
		if(merge) {
			BufferedImage image = mergeImages(images);
			images.clear();
			images.add(image);
		}
		//保存到本地
		for (int i = 0, len = images.size(); i < len; i++) {
			//输出格式: [文件夹路径]/[pdf文件名]_0001.jpg
			ImageIO.write(images.get(i), format, new File(
					sb.append(destPath)
							.append(pdfFileName).append("_").append(String.format("%02d", i + 1))
							.append(".").append(format).toString()));
			sb.setLength(0);
		}
	}

	private BufferedImage mergeImages(List<BufferedImage> images){
		int width = 0, height = 0;
		for(BufferedImage image : images){
			width = image.getWidth() > width ? image.getWidth() : width;
			height += image.getHeight();
		}
		BufferedImage pdfImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
		Graphics2D g2d = pdfImage.createGraphics();
		height = 0;
		for(BufferedImage image :images){
			g2d.drawImage(image, (width - image.getWidth()) / 2, height, image.getWidth(), image.getHeight(), null);
			height += image.getHeight();
		}
		g2d.dispose();
		return pdfImage;
	}

	private List<BufferedImage> pdfToImage(File file, float dpi) throws IOException {
		List<BufferedImage> imgList = null;
		PDDocument pdDocument = null;
		BufferedImage image;
		try {
			System.out.println("路径"+file);
			pdDocument = PDDocument.load(file);
			PDFRenderer renderer = new PDFRenderer(pdDocument);
			int numPages = pdDocument.getNumberOfPages();
			imgList = new ArrayList<BufferedImage>();
			for (int i = 0; i < numPages; i++) {
				image = renderer.renderImageWithDPI(i, dpi);
				if (null != image) {
					imgList.add(image);
				}
			}
		} catch (IOException e) {
			//log.error("convert pdf pages to images failed.", e);
			//FIXME
			throw e;
		} finally {
			try {
				if (null != pdDocument) {
					pdDocument.close();
				}
			} catch (IOException e) {
				//log.error("close IO failed when convert pdf pages to images.", e);
				//FIXME
				throw e;
			}
		}
		return imgList;
	}

	/**
	 *  图片逆转90度
	 * @param imgPath
	 * @return
	 */
	public static  String reversalImage(String imgPath) throws IOException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		String invoice_no = sdf.format(new Date());
		File file = new File(imgPath);
		File outFile = new File(imgPath.replace(".png", "")+invoice_no+".png");
		BufferedImage image2 = ImageIO.read(file);

		int width = image2.getWidth();
		int height = image2.getHeight();
		BufferedImage bufferedImage = new BufferedImage(height,width, image2.getType());
		for (int i = 0; i < width; i++){
			for (int j = 0; j < height; j++){
				bufferedImage.setRGB(j,width-i-1, image2.getRGB(i, j));}}
		ImageIO.write(bufferedImage, "png", outFile);
		return  imgPath;
	}

	public static Map<String, String> checkDegree(String parentName, String parentdegree){
		String host = "https://idcardcert.market.alicloudapi.com";
		String path = "/idCardCert";
		String method = "GET";
		String appcode = "a336a82ae1bf47d2a03c9bae97276101";
		Map<String, String> headers = new HashMap<String, String>();

		headers.put("Authorization", "APPCODE " + appcode);
		Map<String, String> querys = new HashMap<String, String>();
		querys.put("idCard", parentdegree);
		querys.put("name", parentName);

		Map<String,String> checkResult = new HashMap<String, String>();
		try {
			HttpResponse response =  HttpUtils.doGet(host, path, headers, querys);
			System.out.println(response.toString());//如不输出json, 请打开这行代码，打印调试头部状态码。
			//状态码: 200 正常；400 URL无效；401 appCode错误； 403 次数用完； 500 API网管错误
			//获取response的body

			checkResult.put("statusCode", response.getStatusLine().getStatusCode()+"");
			JSONObject jsStr = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
			System.out.println(jsStr.toString());
			checkResult.put("status", (String) jsStr.get("status"));
			System.out.println(checkResult.toString());

		}
		catch (Exception e) {
			e.printStackTrace();// TODO: handle exception
		}
		return checkResult;
	}


	public static boolean doGetSMS(String host, String path,Map<String, String> headers,
								   Map<String, String> querys) throws ClientProtocolException, IOException{

		HttpGet httpGet=new HttpGet(host+path+"?"+"parentPhone="+querys.get("parentPhone")
				+"&parentName="+querys.get("parentName")+"&invoiceNo="+querys.get("invoiceNo"));
			/*for (Map.Entry<String, String> e : headers.entrySet()) {
				httpGet.addHeader(e.getKey(), e.getValue());
	        }*/

		CloseableHttpClient httpCilent = HttpClients.createDefault();
		HttpResponse  response = httpCilent.execute(httpGet);
		int statusCode = response.getStatusLine().getStatusCode();
		if (statusCode==200) {
			return true;
		}
		return false;
	}

	//一对一服务通知签署发送短信
	public static boolean doPostSMS(String host, String path,Map<String, String> headers,
									Map<String, String> querys) throws ClientProtocolException, IOException{

		CloseableHttpClient httpCilent = HttpClients.createDefault();
		HttpPost request = new HttpPost(host+path);

		List<NameValuePair> nvps = new ArrayList<>();
		for (Map.Entry<String,String> entry :querys.entrySet()
		) {
			nvps.add(new BasicNameValuePair(entry.getKey(),entry.getValue()));
		}
		request.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));

		List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();

		for (String key : querys.keySet()) {
			nameValuePairList.add(new BasicNameValuePair(key, querys.get(key)));
		}
		HttpResponse  response =httpCilent.execute(request);
		int statusCode = response.getStatusLine().getStatusCode();
		if (statusCode==200) {
			return true;
		}
		return false;
	}
	/**
	 * 删除某个文件夹下的所有文件夹和文件
	 *
	 * @param delpath
	 *            String
	 * @throws FileNotFoundException
	 * @throws IOException
	 * @return boolean
	 */
	public static boolean deleteFile(String delpath) throws Exception {
		try {

			File file = new File(delpath);
			// 当且仅当此抽象路径名表示的文件存在且 是一个目录时，返回 true
			if (!file.isDirectory()) {
				file.delete();
			} else if (file.isDirectory()) {
				String[] filelist = file.list();
				for (int i = 0; i < filelist.length; i++) {
					File delfile = new File(delpath + "/" + filelist[i]);
					if (!delfile.isDirectory()) {
						delfile.delete();
						System.out.println(delfile.getAbsolutePath() + "删除文件成功");
					} else if (delfile.isDirectory()) {
						deleteFile(delpath + "/" + filelist[i]);
					}
				}
				System.out.println(file.getAbsolutePath() + "删除成功");
				file.delete();
			}

		} catch (FileNotFoundException e) {
			System.out.println("deletefile() Exception:" + e.getMessage());
		}
		return true;
	}
}  




